Skip to content

fix: android auto responsive sheet size #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

lovegaoshi
Copy link

this PR implements the strategy mentioned in #192 (comment) to auto adjust bottom sheet height on content height change. I replaced when the only size is "auto"'s bottomsheetbehavior to COLLAPSED instead of EXPANDED, so its height can be adjusted after the sheet is shown.

test is done using a custom component in my app instead of the test code mentioned in the above PR/linked issue, but the idea is the same.

Screen.Recording.2025-07-01.204012.mp4

Copy link

vercel bot commented Jul 2, 2025

@lovegaoshi is attempting to deploy a commit to the Jovanni's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

codeclimate bot commented Jul 2, 2025

Code Climate has analyzed commit a7bbe47 and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1
Duplication 2

View more on Code Climate.

@lodev09
Copy link
Owner

lodev09 commented Jul 2, 2025

Thanks @lovegaoshi. I'll test over the weekend.

@lodev09
Copy link
Owner

lodev09 commented Jul 6, 2025

@lovegaoshi tested and works. however, it is now draggable to full screen height. Can we disable that and have it draggable up until specified max height?

@lovegaoshi
Copy link
Author

I dont know if that is technically feasible - that requires changing maxHeight which per documentation should only be specified when the sheet is closed. Perhaps there are hacks that either

  • disable bottomsheet.behavior.EXPANDED
  • or combine this with the setMaxHeight approach from Make android sheet reactive to height changes #192 on content size change hoping as bottomsheet.behavior is still in COLLAPSED it wont trigger layout changes.
    but anyways i suspect hacks will be involved.

@lodev09
Copy link
Owner

lodev09 commented Jul 7, 2025

Yeah, try 2nd option. It might be advised to only set maxHeight when closed due for UX purposes since it can't be animated (bad UI for the user). Since we don't get any error so I guess it's kinda "ok" 😅

@lovegaoshi
Copy link
Author

lovegaoshi commented Jul 8, 2025

ok. i actually got it working but its very hacked to me.

we already saw #192 doesnt give you an animation. the issue is bottomSheetBehavior.state === EXPANDED will NOT animate. only COLLAPSED with seekHeight animates.

actually if instead of using EXPANDED in #192 but use COLLAPSED, and put bottomSheet.state = COLLAPSED before setting the bottomsheetView.layout, this will work for half the problem - 'collapse' (content from high to low height) will animate but 'expand' (low to high) will not

then I have a very hacky solution that sets the height to -2 then use a bottomSheetCallback monitoring the first time onSlide triggers with offset = 0 (finished sliding) to set layout height. it works both ways now, but its quite a mess.

solution 1: (see how onSlide does not log on expand anymore)

Screencast.from.07-08-2025.04.22.24.PM.webm

solution 2:

Screencast.from.07-08-2025.04.21.30.PM.webm

@lodev09
Copy link
Owner

lodev09 commented Jul 9, 2025

Have you tried intercepting touch gesture?

@lovegaoshi
Copy link
Author

im not comfortable writing an ontouch intercept logic to effectively disable bottomsheet.behavior.EXPANDED, ideas welcome

i did set maxHeight to -1 instead of value + footerHeight in the 2nd approach - if view.layout.height just has to be slightly higher than peekHeight to trigger the animation, this could be an easy solution. otherwise i guess fixing the layout height in onSlide is the only way out

this sets layout.height right after STATE.COLLAPSED is set to give an animation effect. sometimes janky.
@lovegaoshi
Copy link
Author

i spent a bit more time and found some leads. though im sorta lost here and need another pair of eyes.

I did confirm my hypothesis that view.layout.height just has to be slightly higher than peekHeight to trigger the animation - presented in solution 1, I override truesheetview.layout.height to peekHeight + 1 to give an animation. but this animation is janky in my testings. expand doesnt expand quite to the exact hight and collapse is too fast.

the solution 2 is the hacky solution i mentioned before - only override truesheetview.layout.height to peekheight AFTER the first completed onSlide (which is the animation trigger from content size change). this way bc collapse no longer overrides the layout up front, the animation is a lot smoother; and for unexplained reasons now the expand can also expand to full length. the downside is extra complicated code logic and obviously user scrolls during animation will have side effects. of course I can also do a isDraggable = false then set it to true.

@lodev09
Copy link
Owner

lodev09 commented Jul 9, 2025

@lovegaoshi I agree, animating size change is too hacky. Let's just stick with no-animation approach. I've committed to simplify things, hope you don't mind :)

@lovegaoshi
Copy link
Author

lovegaoshi commented Jul 9, 2025 via email

@lodev09
Copy link
Owner

lodev09 commented Jul 9, 2025

Go for it! Although you might as well use ['auto', 'large'] if you really want that animation.
I did try various combinations but couldn't find any stable solution. Test it using the PrompSheet example :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants